﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __C1F8B13F_3A44_4c49_A776_CE4056CBC8D5__
#define __C1F8B13F_3A44_4c49_A776_CE4056CBC8D5__

#include "../tools/head.h"

namespace xos_box
{
    // 
    // buf interface
    // 
    class buf_impl : public xos_stl::mem_item< xos::release_impl< buf_impl >, thread_lock >,
        public xos_box::i_buf
    {
    public:
        typedef xos::release_impl< buf_impl > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_addr( POOL *** pppPool, LIST *** pppList );

    public:
        buf_impl();
        ~buf_impl();

    public:
        // 
        // buf variable
        // 
        WSABUF m_wsa_buf;
        char m_szBuf[BUF_SIZE+1024];
        int m_nLen;
        int m_nPos;

    public:
        int init();
        int term();

    public:
        // 
        // read data
        // 
		char * get_data( char * lpszData, int nLen, int * lpnLenNeeded );
		int get_data( xos_box::i_big_buf * pBuf, int * lpnLenNeeded );
		int get_data( xos_box::i_buf * pBuf, int * lpnLenNeeded );

		int set_data( const char * lpszData, int nLen );
        int set_str( const char * lpszData );
		int set_data( xos_box::i_big_buf * pBuf );
		int set_data( xos_box::i_buf * pBuf );

		int remove_data( char * lpszData, int nWantRemoveSize );
		int remove_data( xos_box::i_big_buf * pBuf, int nWantRemoveSize );
		int remove_data( xos_box::i_buf * pBuf, int nWantRemoveSize );

		int add_data( const char * lpszData, int nLen );
        int add_str( const char * lpszData );
		int add_data( xos_box::i_big_buf * pBuf );
		int add_data( xos_box::i_buf * pBuf );

        int get_data_from_list( xos_box::i_list * pList );
        int put_data_to_list( xos_box::i_list * pList, bool bFront );

        WSABUF * get_wsa_buf( WSABUF ** lppWsaBuf );
		int move_data_to_begin();

        // 
        // get data len
        // 
        int get_len( int * lpnDataLen );
        int set_len( int nLen );

        // 
        // set pos;
        // 
        int get_pos( int * lpnPos );
        int set_pos( int xPos );

        // 
        // get buf size. total buf size
        // 
        int get_buf_size( int * lpnBufLen );
    };
}

#endif // __C1F8B13F_3A44_4c49_A776_CE4056CBC8D5__
